package models

import (
	"github.com/robfig/cron/v3"
	"manageCrontab/lib/localtime"
	"time"
)

// 定时任务表
type Crontab struct {
	CrontabId   string    `gorm:"size:20;PRIMARY_KEY;"`
	CrontabName string    `gorm:"size:50;not null;comment:'定时任务名称'"`
	CrontabSpec string    `gorm:"size:30;not null;comment:'定时时间'"`
	Description string    `gorm:"type:text;comment:'定时任务描述'"`
	RunStatus   int       `gorm:"type:tinyint(1);default:0;comment:'运行状态，0：新增加任务,1: 运行中， 2：停止'"`
	CrontabType string    `gorm:"type:varchar(20);not null;comment:'定时任务类型，email：发送邮件，cmd：调用命令行'"`
	CrontabData string    `gorm:"type:text;comment:'定时任务所需的数据'"`
	RunCount    int       `gorm:"default:0;comment:'运行次数,停止后请删除该次数'"`
	RunLastTime time.Time `gorm:"default:null;comment:'最后运行时间'"`
	IsValid     int       `gorm:"type:tinyint(1);not null;default:1"`
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type EmailInfo struct {
	MailTo  []string `json:"mailTo"`
	Subject string   `json:"subject"`
	Body    string   `json:"body"`
}

// 定时任务表
type Task struct {
	TaskId       string              `gorm:"size:20;PRIMARY_KEY;"`
	EntryID      cron.EntryID        `gorm:"type:int(11);default:null;comment:'执行定时任务的id'"`
	TaskName     string              `gorm:"size:50;not null;comment:'定时任务名称'"`
	TaskSpec     string              `gorm:"size:30;not null;comment:'定时时间'"`
	TaskDescript string              `gorm:"type:text;comment:'定时任务描述'"`
	TaskStatus   int                 `gorm:"type:tinyint(1);default:0;comment:'运行状态，0：新增加任务,1: 运行中， 2：停止'"`
	TaskType     string              `gorm:"type:varchar(20);not null;comment:'定时任务类型，email：发送邮件，cmd：调用命令行'"`
	TaskData     string              `gorm:"type:text;comment:'定时任务所需的数据'"`
	RunCount     int                 `gorm:"default:0;comment:'运行次数,停止后请删除该次数'"`
	RunLastTime  localtime.LocalTime `gorm:"default:null;comment:'最后运行时间'"`
	TaskRunTime  int                 `gorm:"default:0;comment:'任务执行时间，单位秒'"`
	IsValid      int                 `gorm:"type:tinyint(1);not null;default:1"`
	CreatedAt    localtime.LocalTime
	UpdatedAt    localtime.LocalTime
}
